//
//  HPHot.m
//  wedding
//
//  Created by 常宽 on 15/1/16.
//  Copyright (c) 2015年 常宽. All rights reserved.
//

#define WIDTH self.frame.size.width
#define HEIHT self.frame.size.height

#import "HPHot.h"
#import "HomePageModel.h"//model类

@interface HPHot ()
/// 封面图片
@property (nonatomic, retain)UIImageView *HPHotImageView;
/// 标题
@property (nonatomic, retain)UILabel *HPHotTitle;
/// 时间
@property (nonatomic, retain)UILabel *HPHotTime;
/// 地点
@property (nonatomic, retain)UILabel *HPHotAddress;
/// 头像
@property (nonatomic, retain)UIImageView *HPHotPortrait;
/// by 昵称
@property (nonatomic, retain)UILabel *HPHotName;

@end

@implementation HPHot

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        //封面
        self.HPHotImageView = [[UIImageView alloc]init];
        [self addSubview:_HPHotImageView];
        //标题
        self.HPHotTitle = [[UILabel alloc]init];
        [self.HPHotImageView addSubview:_HPHotTitle];
        //时间
        self.HPHotTime = [[UILabel alloc]init];
        [self.HPHotImageView addSubview:_HPHotTime];
        //地点
        self.HPHotAddress = [[UILabel alloc]init];
        [self.HPHotImageView addSubview:_HPHotAddress];
        //作者
        self.HPHotName = [[UILabel alloc]init];
        [self.HPHotImageView addSubview:_HPHotName];
        //头像
        self.HPHotPortrait = [[UIImageView alloc]init];
        [self.HPHotImageView addSubview:_HPHotPortrait];
        
    }
    return self;
}

- (void)layoutSubviews
{//进行布局
    [super layoutSubviews];
    //封面
    self.HPHotImageView.frame = self.bounds;
    self.HPHotImageView.clipsToBounds = YES;
    self.HPHotImageView.contentMode = UIViewContentModeScaleAspectFill;
    

    
    //标题
    self.HPHotTitle.frame = CGRectMake(10, HEIHT - 20, WIDTH - 20, 20);
    self.HPHotTitle.backgroundColor = [[WebColor black]colorWithAlphaComponent:0.3];
        /*字体*/
    self.HPHotTitle.textColor = [WebColor lavenderBlush];
    self.HPHotTitle.font = [UIFont boldSystemFontOfSize:15];
    
    //醒目
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(12, 5, 3, 20)];
    view.backgroundColor = [WebColor crimson];
    [self addSubview:view];
    //时间
    self.HPHotTime.frame = CGRectMake(15, 5, WIDTH / 6, 10);
    self.HPHotTime.backgroundColor = [[WebColor black]colorWithAlphaComponent:0.3];
        /*字体*/
    self.HPHotTime.textColor = [WebColor lavenderBlush];
    self.HPHotTime.font = [UIFont boldSystemFontOfSize:8];

    
    //地点
    self.HPHotAddress.frame = CGRectMake(15, 15, WIDTH / 6, 10);
    self.HPHotAddress.backgroundColor = [[WebColor black]colorWithAlphaComponent:0.3];
        /*字体*/
    self.HPHotAddress.textColor = [WebColor lavenderBlush];
    self.HPHotAddress.font = [UIFont boldSystemFontOfSize:8];

    
    //头像
    self.HPHotPortrait.frame = CGRectMake(WIDTH - 70, 5, 40, 40);
    self.HPHotPortrait.backgroundColor = [WebColor lightCyan];
    self.HPHotPortrait.layer.cornerRadius = 20;
    self.HPHotPortrait.clipsToBounds = YES;
    
    //作者
    self.HPHotName.frame = CGRectMake(WIDTH - 80, 45, 60, 10);
    self.HPHotName.backgroundColor = [[WebColor black]colorWithAlphaComponent:0.3];
        /*字体*/
    self.HPHotName.textColor = [WebColor lavenderBlush];
    self.HPHotName.font = [UIFont boldSystemFontOfSize:8];

}

- (void)xxxxchuanzi:(HomePageModel *)model
{
    //封面
    NSURL *imageURL = [NSURL URLWithString:model.coverpath];
    [self.HPHotImageView sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"NoPicture.jpg"]];
    //标题
    self.HPHotTitle.text = model.subject;
    //结婚时间
    self.HPHotTime.text = [NSString stringWithFormat:@" %@", model.marrydate];
    //结婚城市
    self.HPHotAddress.text =[NSString stringWithFormat:@" %@", model.city];
    //作者头像
    NSURL *porUrl = [NSURL URLWithString:model.avatar];
    [self.HPHotPortrait sd_setImageWithURL:porUrl placeholderImage:[UIImage imageNamed:@"测试-头像.jpg"]];
    //作者名
    self.HPHotName.text = [NSString stringWithFormat:@" by %@", model.author];
}






/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
